package com.qiyadeng.company.biz;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.List;

import junit.framework.Assert;

import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;

public class TestMmtService {

	@Ignore
	public void testGetBalanceFromXml() throws FileNotFoundException, IOException{
		String fileString = IOUtils.toString(new FileInputStream(new File("src/main/java/com/qiyadeng/company/biz/selectCardBalance.xml")));
		//System.out.println(fileString);
		RespCardInfo2 rci = RespCardInfo2.getCardInfo2FromXmlString(fileString);
		System.out.println("balacne is :" + rci.getInformation().getCardbalance());
		Assert.assertEquals(rci.getInformation().getCardbalance(), "2899.59");
	}
	
	@Ignore
	public void GetSelectUserFromXml() throws FileNotFoundException, IOException{
		String fileString = IOUtils.toString(new FileInputStream(new File("src/main/java/com/qiyadeng/company/biz/selectuser.xml")));
		ResSelectUser user = ResSelectUser.getResSelectUserFromXml(fileString);
		Assert.assertNotNull(user);
		//Assert.assertEquals("700760011676", user.getInformation().getCardlist().get(0).getCardno());
	}
	
	@Ignore
	public void testGetBalance(){//查询余额
		String cardNo = "202600000042";
		String password = "";
		MmtService mmt = new MmtService();
		String balance = mmt.getCardBalance(cardNo, password);
		System.out.println("balacne is :"+ balance);
	}
	
	@Ignore //查询优惠券
	public void testQueryTicket(){
		MmtService mmt = new MmtService();
		List<RespQueryTicket> tickets = mmt.queryCardTicket("700750045613");
		if(tickets != null && tickets.size()>0){
			System.out.println("I have ticket");
		}
	}
	
	@Ignore
	public void getUserInfo(){
		MmtService mmt = new MmtService();
		ResSelectUser rsu = mmt.selectUserInfo("700750045613", null, null, null);
		Assert.assertNotNull(rsu);
		Assert.assertEquals("谢卿卿", rsu.getInformation().getName());
	}
	
	@Ignore
	public void getUserInfoByPhone(){
		MmtService mmt = new MmtService();
		ResSelectUser rsu = mmt.selectUserInfo(null, null, "18616708172", null);
		Assert.assertNotNull(rsu);
		//Assert.assertEquals("谢卿卿", rsu.getInformation().getName());
	}
	
	@Test
	public void grantTicket(){
		MmtService mmt = new MmtService();
		RespGrantTicket ticket = mmt.grantTicket("13564303627");
		TicketGrant tg= ticket.getTickets().get(0);
		System.out.println(tg.getTicketName()+":"+tg.getTicketNo());
	}
	
	
	@Ignore
	public void GetSendSms(){
		MmtService mmt = new MmtService("sms");
		//mmt.selectUserInfo("700750045613", "", "", "");
		//mmt.queryCardTicket("700750045613");
		mmt.sendSms("18616018007", "你好啊");
	}
	
	@Ignore
	public void testSomething(){
		String s = "微信注册送好礼：任意热饮第二杯半价，券号：{0}该电子券有效期自发放日起三个月内有效【爱茜茜里】";
		s = MessageFormat.format(s, "11111111111111");
		System.out.println(s);
	}
}
